package hu.myai.triggers.coverlong;

import hu.myai.api.tick.AbstractTickProvider;
import hu.myai.api.triggers.AbstractTrigger;
import hu.myai.indicators.GapSizeIndicator;
import hu.myai.indicators.tick.TickShadowRateIndicator;
import hu.myai.indicators.tick.TickVolumeChangeIndicator;
import hu.myai.model.IndicatorVO;
import hu.myai.model.TriggerVO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 1. open higher with gap<br>
 * 2. down pattern with upper shadow 3. more than double volume than previous 4.
 * bearish or side trend
 * 
 * @author bozbalint
 * 
 * */
public class HighVolumeAndGapTrigger extends AbstractTrigger {

	/**
	 * The object used when logging debug,errors,warnings and info.
	 * */
	private final Logger log = LoggerFactory.getLogger(this.getClass());

	private String shadowID;

	private String volumeID;

	private String gapSizeID;

	public HighVolumeAndGapTrigger(String name, AbstractTickProvider tick) {
		super(name, tick);
		shadowID = register(new TickShadowRateIndicator(null));
		volumeID = register(new TickVolumeChangeIndicator());
		gapSizeID = register(new GapSizeIndicator());
	}

	@Override
	protected TriggerVO triggerCalculation() {

		IndicatorVO bsrIndicator = indicatorMap.get(shadowID);
		if (bsrIndicator == null)
			return null;

		IndicatorVO vcIndicator = indicatorMap.get(volumeID);
		if (vcIndicator == null)
			return null;

		IndicatorVO gsIndicator = indicatorMap.get(gapSizeID);
		if (gsIndicator == null)
			return null;

		if (bsrIndicator.getValue() < 2.5 && vcIndicator.getValue() > 2.5 && gsIndicator.getValue() > 0.02) {

			TriggerVO trigger = new TriggerVO();
			trigger.setTick(lastTick);
			trigger.setRisk(20);
			trigger.setTradeType(TriggerVO.BUY_ONMARKET);

			log.debug(trigger.toString());
			return trigger;
		}
		return null;
	}
}
